home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / ctutor2.zip / SUMSQRES.C < prev    next >
C/C++ Source or Header  |  1987-07-04  |  866b  |  34 lines

  1.                                           /* Chapter 5 - Program 1 */
  2. int sum; /* This is a global variable */
  3.  
  4. main()
  5. {
  6. int index;
  7.  
  8.    header();        /* This calls the function named header */
  9.    for (index = 1;index <= 7;index++)
  10.      square(index); /* This calls the square function */
  11.    ending();        /* This calls the ending function */
  12. }
  13.  
  14. header()        /* This is the function named header */
  15. {
  16.    sum = 0;     /* Initialize the variable "sum" */
  17.    printf("This is the header for the square program\n\n");
  18. }
  19.  
  20. square(number)   /* This is the square function */
  21. int number;
  22. {
  23. int numsq;
  24.  
  25.    numsq = number * number;  /* This produces the square */
  26.    sum += numsq;
  27.    printf("The square of %d is %d\n",number,numsq);
  28. }
  29.  
  30. ending()   /* This is the ending function */
  31. {
  32.    printf("\nThe sum of the squares is %d\n",sum);
  33. }
  34.